﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;

namespace TypingG
{
    class SQLServer
    {
        private static SqlConnection con;
        private static SqlDataAdapter sd = new SqlDataAdapter();
        public static void Start(string DataSource,string DatabaseName)
        {
            string sour = "Data Source=" + DataSource + ";" + "Initial Catalog=" + DatabaseName + ";" + "Integrated Security=TRUE";
            con = new SqlConnection(sour);
           
        }
        public static void addAcc(string hoten,string cmnd,string namsinh)
        {
            sd.InsertCommand = new SqlCommand("INSERT INTO KhachHang VALUES (@FullName,@CMND,@NamSinh)", con);
            sd.InsertCommand.Parameters.Add("@FullName", System.Data.SqlDbType.NVarChar).Value = hoten;
            sd.InsertCommand.Parameters.Add("@CMND", System.Data.SqlDbType.VarChar).Value = cmnd;
            sd.InsertCommand.Parameters.Add("@NamSinh", System.Data.SqlDbType.VarChar).Value = namsinh;
            con.Open();
            sd.InsertCommand.ExecuteNonQuery();
            
            con.Close();

        }
        public static void addID(string ID, string CMND)
        {
            sd.InsertCommand = new SqlCommand("INSERT INTO TaiKhoan VALUES (@ID,@CMND)", con);
            sd.InsertCommand.Parameters.Add("@ID", System.Data.SqlDbType.VarChar).Value = ID;
            sd.InsertCommand.Parameters.Add("@CMND", System.Data.SqlDbType.VarChar).Value = CMND;
            con.Open();
            sd.InsertCommand.ExecuteNonQuery();
            con.Close();

        }
        public static void addIDLevel(string ID, string Pass, string Level)
        {
            sd.InsertCommand = new SqlCommand("INSERT INTO CapDoTaiKhoan VALUES (@ID,@Pass,@Capdo)", con);
            sd.InsertCommand.Parameters.Add("@ID", System.Data.SqlDbType.VarChar).Value = ID;
            sd.InsertCommand.Parameters.Add("@Pass", System.Data.SqlDbType.VarChar).Value = Pass;
            sd.InsertCommand.Parameters.Add("@Capdo", System.Data.SqlDbType.VarChar).Value = Level;
            con.Open();
            sd.InsertCommand.ExecuteNonQuery();
            con.Close();
        }
        public static void ShowData(System.Windows.Forms.DataGridView dg,string table)
        {
            DataSet ds = new DataSet();
            string synTable = "SELECT * FROM " + table;
            sd.SelectCommand = new SqlCommand(synTable,con);
            ds.Clear();
            sd.Fill(ds);
            dg.DataSource = ds.Tables[0];
        }
        
    }
}
